package util

import (
	"sort"
	"strings"
)

func Unique[C any](arr []C) []C {
	var d = make(map[any]bool)
	var res []C
	for _, c := range arr {
		if _, ok := d[c]; !ok {
			res = append(res, c)
			d[c] = true
		}
	}
	return res
}

func ArrayStringToMD5(arr []string) string {
	var newArr = make([]string, len(arr))
	copy(newArr, arr)
	sort.Strings(newArr)
	newStr := strings.Join(newArr, "-")
	return Md5(newStr, false)
}

func InArray[C comparable](a C, arr []C) bool {
	for _, v := range arr {
		if a == v {
			return true
		}
	}
	return false
}
